<?php

/**
 * 逻辑区：轮播广告相关
 * @copyright (C)2011 Cenwor Inc.
 * @author fengwei
 * @package logic
 * @name lunboad.logic.php
 * @version 1.0
 */

class TopicLogic
{
	
	public function GetOne($id)
	{
		$sql = 'SELECT * from  '.table('topic').' where topic_id='.$id;
		$info = dbc(DBCMax)->Query($sql)->limit(1)->done();
		/* if( $info['end_time'] < time()){
			$info['status'] = 0;
		} */
		return $info;
	}
	
	public function display($topic_id=0){
		if (!$topic_id) {
			return false;
		}
		$topic_info = logic('topic')->GetOne($topic_id);
		if ($topic_info) {
			return $topic_info;
		}else{
			return false;
		}
	}
	
	public function Add($ary)
	{

		/* $data = array(
				

				'ad_img' => $ad_img,
				'ad_link' => $ad_link,
				'city_id' => $city_id,
				'sort'=>$sort,
		);
		if ($ad_text) {
			$data['ad_text']=$ad_text;
		} */
		if (is_array($ary)) {
			dbc()->SetTable(table('topic'));
			return dbc()->Insert($ary);
		}else{
			return false;
		}
		
	}
	
	
	 public function GetList()
	{
		$city_id = logic('misc')->City('id');
		
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' WHERE'.$sql_limit_user.' ORDER BY sort limit 5';
		

		$topic_list = dbc(DBCMax)->query($sql)->done();
		
		include handler('template')->file('@html/lbad/list');
		//include handler('template')->file('lbad_list');

		
	} 
	
	public function Get_ddc_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=1 and t.display=1 ORDER BY sort limit 10';
		$flag = "ddc";
		$lc_text = "电动车";
		$list = dbc(DBCMax)->query($sql)->done();
		$p1=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('ddc'),1000,2000);
		$p2=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('ddc'),2000,3000);
		$p3=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('ddc'),3000,10000);	
		if (is_array($list)) {
			$list = $this->make_links($list);
			
			include handler('template')->file('catalog_index_list');
		}
			
	
	}
	
	public function Get_kc_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=56 and t.display=1 ORDER BY sort limit 10';
	
		$flag = "kuche";
		$lc_text = "酷车";
		$list = dbc(DBCMax)->query($sql)->done();
		$p1=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('kuche'),2000,3000);
		$p2=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('kuche'),3000,4000);
		$p3=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('kuche'),4000,20000);
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('catalog_index_list');
		}
	
	
	}
	
	public function Get_zxc_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=3 and t.display=1 ORDER BY sort limit 10';
	
		$flag = "zxc";
		$lc_text = "自行车";
		$list = dbc(DBCMax)->query($sql)->done();
		$p1=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('zxc'),200,1000);
		$p2=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('zxc'),1000,2000);
		$p3=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('zxc'),2000,20000);
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('catalog_index_list');
		}
	
	
	}
	
	public function Get_tc_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=16 and t.display=1 ORDER BY sort limit 10';
	
		$flag = "tongche";
		$lc_text = "童车";
		$list = dbc(DBCMax)->query($sql)->done();
		$p1=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('tongche'),50,200);
		$p2=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('tongche'),200,500);
		$p3=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('tongche'),500,10000);
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('catalog_index_list');
		}
	
	
	}
	
	public function Get_ddqc_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=20 and t.display=1 ORDER BY sort limit 10';
	
		$flag = "ddqc";
		$lc_text = "电动汽车";
		$list = dbc(DBCMax)->query($sql)->done();
		$p1=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('ddqc'),10000,30000);
		$p2=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('ddqc'),30000,50000);
		$p3=logic('product')->GetIndexCatList($city_id,logic('catalog')->Filter('ddqc'),50000,1000000);
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('catalog_index_list');
		}
	
	
	}
	
	
	public function Get_lnc_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=19 and t.display=1 ORDER BY sort';
	
		$flag = "lnc";
		$list = dbc(DBCMax)->query($sql)->done();
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('topic_index_list');
		}
	
	
	}
	
	
	public function Get_hw_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=21 and t.display=1 ORDER BY sort';
	
		$flag = "hw";
		$list = dbc(DBCMax)->query($sql)->done();
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('topic_index_list');
		}
	
	
	}
	
	public function Get_pj_list()
	{
		$city_id = logic('misc')->City('id');
	
		$sql_limit_city = '1';
		if ($city_id > 0)
		{
			$sql_limit_user = ' city_id = '.$city_id;
		}
		$sql = 'SELECT * from  '.table('topic').' t INNER JOIN  '.table('catalog').' c ON t.cat_id=c.id WHERE'.$sql_limit_user.' and c.parent=22 and t.display=1 ORDER BY sort';
	
		$flag = "pj";
		$list = dbc(DBCMax)->query($sql)->done();
		if (is_array($list)) {
			$list = $this->make_links($list);
			include handler('template')->file('topic_index_list');
		}
	
	
	}
	
	
	
	private function make_links($places)
	{
		foreach ($places as $i => $item)
		{
			/* $places[$i]['url'] = logic('url')->create('product', array('region' => $region['id'], 'street' => null));
			if (isset($region['streets']))
			{
				foreach ($region['streets'] as $ii => $street)
				{
					$places[$i]['streets'][$ii]['url'] = logic('url')->create('product', array('street' => $street['id']));
				}
			} */
			$places[$i]['url'] = logic('url')->create('topic', array('mod' =>'topic','tid' => $item['topic_id'], 'cid' => $item['cat_id']));
		}	
		return $places;
	}
	
	
	
	
	
	
}
?>